/**
 * Copyright (C), 2012-2018, 联奕科技有限公司
 * FileName: WebConfig
 * Author:   石贵武
 * Date:     2018\3\7 0007 19:17
 * Description:
 * History:
 * <author>          <time>          <version>          <desc>
 * 作者姓名           修改时间           版本号              描述
 */
package com.zhoudongxiu.web.webconfig;

import com.zhoudongxiu.web.filter.TimeFilter;
import com.zhoudongxiu.web.handler.TimeInterceptor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.web.servlet.FilterRegistrationBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;
import org.springframework.web.servlet.mvc.WebContentInterceptor;

import javax.servlet.FilterRegistration;
import java.util.ArrayList;
import java.util.List;

/**
 * 〈一句话功能简述〉<br>
 * 〈〉
 *
 * @author 石贵武
 * @create 2018\3\7 0007
 * @since 1.0.0
 */
@Configuration
public class WebConfig extends WebMvcConfigurerAdapter{

    @Autowired
    private TimeInterceptor timeInterceptor;

    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        registry.addInterceptor(timeInterceptor);

    }

    @Bean
    public FilterRegistrationBean getMyFilter() {
        /**
         * 功能描述: <br>
         * 〈注册第三方Filter〉
         *
         * @param
         * @return:org.springframework.boot.web.servlet.FilterRegistrationBean
         * @since: 1.0.0
         * @Author:
         * @Date: 2018\3\7 0007 19:40
         */
        FilterRegistrationBean filterRegistrationBean = new FilterRegistrationBean();
        TimeFilter timeFilter = new TimeFilter();
        filterRegistrationBean.setFilter(timeFilter);
        List<String> urls = new ArrayList<>();
        urls.add("/*");//截获所以请求
        return filterRegistrationBean;
    }
}